﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SISGEZATBZVisual.BusinessEntities;

namespace SISGEZATBZVisual.Repository.Mapping
{
    public class MatriculaMap:EntityTypeConfiguration<Matricula>
    {
        public MatriculaMap()
        {
            this.HasKey(r => r.Id);

            //propiedades
            this.Property(r => r.Id)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            this.Property(r => r.FechaMatricula)
                .IsRequired();

            this.Property(r => r.Promovido)
               .IsRequired();

            this.Property(c => c.Documentos)
                .HasMaxLength(255)
                .IsRequired();

            this.Property(c => c.Estado)
                .IsRequired();


            this.Property(c => c.IdAñoAcademico)
           .IsOptional();

            //table
            this.ToTable("Matricula");

            //Relaciones
            this.HasRequired(r => r.Seccion)
                .WithMany()
                .HasForeignKey(r => r.IdSeccion)
                .WillCascadeOnDelete(false);

            this.HasRequired(r => r.Alumno)
                .WithMany(r=>r.Matriculas)
                .HasForeignKey(r => r.IdAlumno)
                .WillCascadeOnDelete(false);
            
            this.HasOptional(r => r.AñoAcademico)
                .WithMany(r=>r.Matriculas)
                .HasForeignKey(r => r.IdAñoAcademico)
                .WillCascadeOnDelete(false);

            this.HasOptional(r => r.TrasladoExterno);////
               
        }
    }
}
